program Numbers;
var
  k : longint;

begin
  read(k);
  if k = 1 then writeln(8)
  else
    if k mod 6 = 1 then writeln(4)
    else
      if k mod 3 = 1 then writeln(3)
      else writeln(1);
end.